<h3><?php echo __("Import")?></h3>

<?php if(isset($pendingImports) && $pendingImports && count($pendingImports) > 0)
{?>
	<div>
	<div class="warningMsg">	
		<?php echo __("Some files are pending for their importing to complete.") ?>
	</div>
		<table>
			<tr>
				<th>
					<?php echo __("File name")?>
				</th>
				<th>
					<?php echo __("Started On") ?>
				</th>
				<th>
					<?php echo __("Last ran On") ?>
				</th>
				<th>
					<?php echo __("Action")?>
				</th>
			</tr>
			<?php foreach($pendingImports as $pendingImport){?>
					<tr>
						<td>
							<?php echo $pendingImport['CsvImportFile']['filename']?>
						</td>
						<td>
							<?php echo $pendingImport['CsvImportFile']['created']?>
						</td>
						<td>
							<?php echo $pendingImport['CsvImportFile']['last_ran']?>
						</td>
						<td>
							<?php echo $html->link(__("Continue Import"),array("action"=>"startImporting",$pendingImport['CsvImportFile']['id']))?>
							|  <?php echo $html->link(__("Delete"),array("action"=>"deleteImportFile",$pendingImport['CsvImportFile']['id']),null,__("Are you sure you don't want to import records from this file any further now?"));?>
						</td>
					</tr>
			<?php } ?>
		</table>
		</div>
<?php }?>

<?php

	echo $form->create($importModelAlias,array("url"=>"/".$this->params['url']['url'],'type'=>"file"));
	$fields = cri($importModelAlias)->getFields('group','import');
	$fields = array_combine($fields,$fields);
	unset($fields['file']);
	echo "<div id=\"upload_fields\">";
	echo $form->input("file");
	echo "</div>";
?>
<?php if(isset($localFiles) && count($localFiles) > 0){?>
		<?php echo $form->input('use_local',array('id'=>"use_local_check",'type'=>"checkbox","label"=>__("Use file on the already present on the server?"),'type'=>"checkbox"));?>
		<div id="local_file_fields" style="display:none">
		<?php echo $form->input("local_file",array("type"=>"select",'empty'=>__("-Select-"),'options'=>array_combine($localFiles,$localFiles),'label'=>__("Server File")))?>
		</div>
<?php  }?>
	<?php
		$fields['fieldset'] = false;
		echo $form->inputs($fields);
	?>
<?php
	echo $form->end(__("Import"));
?>

<script>
	$(document).ready(function(){
		var fn = function()
		{
			if($('#use_local_check').attr("checked"))
			{
				$("#local_file_fields").show();
				$("#upload_fields").hide();
				$('#ListingImportFile').val("");
			}else
			{
				$("#local_file_fields").hide();
				$("#upload_fields").show();
			}
		};
		$('#use_local_check').change(fn);
		fn();	
	})
</script>